package ee.project;

import ee.project.BTree.BTree;
import ee.project.avltree.AvlTree;
import ee.project.redblacktree.RedBlackTree;

public class TreeTestClass {

	public static void main(String[] args) {
		TreeTestClass ttc = new TreeTestClass();
		ttc.runTests();
	}

	private void runTests() {
		AvlTree avlTree = new AvlTree();
		RedBlackTree rbTree = new RedBlackTree(Integer.MIN_VALUE);
		Stopwatch timer = new Stopwatch();

		int NUMS = 1000000;
		final int GAP = 37;

		for (int j = 0; j < 10; j++) {
			System.out.println("Number of elements: " + NUMS);

			System.out.println("Arbitrary adding");
			timer.start();
			for (int i = GAP; i != 0; i = (i + GAP) % NUMS) {
				avlTree.insert(new Integer(i));
			}

			timer.stop();
			System.out.println("AVL tree insert: " + timer.getTimeElapsed()
					+ "ms");

			timer.reset().start();
			for (int i = GAP; i != 0; i = (i + GAP) % NUMS) {
				rbTree.insert(new Integer(i));
			}
			timer.stop();
			System.out.println("RedBlack tree insert: "
					+ timer.getTimeElapsed() + "ms");

			System.out.println();
			avlTree.makeEmpty();
			rbTree.makeEmpty();

			System.out.println("Incremental adding");
			timer.start();
			for (int i = 1; i <= NUMS; i++) {
				avlTree.insert(new Integer(i));
			}
			timer.stop();
			System.out.println("AVL tree insert: " + timer.getTimeElapsed()
					+ "ms");

			timer.reset().start();
			for (int i = 1; i <= NUMS; i++) {
				rbTree.insert(new Integer(i));
			}
			timer.stop();
			System.out.println("RedBlack tree insert: "
					+ timer.getTimeElapsed() + "ms");

			System.out.println();
			avlTree.makeEmpty();
			rbTree.makeEmpty();

			System.out.println("Decremental adding");
			timer.start();
			for (int i = NUMS; i > 0; i--) {
				avlTree.insert(new Integer(i));
			}
			timer.stop();
			System.out.println("AVL tree insert: " + timer.getTimeElapsed()
					+ "ms");

			timer.reset().start();
			for (int i = 0; i < NUMS; i++) {
				rbTree.insert(new Integer(i));
			}
			timer.stop();
			System.out.println("RedBlack tree insert: "
					+ timer.getTimeElapsed() + "ms");
			System.out.println();
			avlTree.makeEmpty();
			rbTree.makeEmpty();
			NUMS = NUMS + 1000000;
		}
	}
}
